package code;

import java.util.HashMap;

public class Node {
	public int category_, // 1:host 2:router
			IPadd_, // IP Address
			routing_alg_; // 1: static 2:dynamic
	Link[] outputlink_ = new Link[10]; // output link
	int No_links_; // number of output link
	HashMap<Integer, RoutingEntry> RoutingTable_ = new HashMap<Integer, RoutingEntry>();
	UDP udp_generator;

	public Node(int category_, int iPadd_, int routing_alg_) {
		this.category_ = category_;
		this.IPadd_ = iPadd_;
		this.routing_alg_ = routing_alg_;
		this.No_links_ = 0;
		System.out.println("Node Generation Complete");
	}
	
	
	void get_pkt_(Packet p) {
		int dest_IP = p.m_destIP_;
		if (RoutingTable_.containsKey(dest_IP)) {
			RoutingEntry routing_entry = RoutingTable_.get(dest_IP);
			for (int i = 0; i < No_links_; i++) {
				if (routing_entry.m_NextNode_ == outputlink_[i].m_destination_.IPadd_)
					outputlink_[i].get_packet_(p);

			}
		} else if (dest_IP == this.IPadd_) {
			System.out.printf("Time %f: Packet Received at node %d, sent at %f s \n", Global.TIME,dest_IP,p.m_pkt_generationtime_);;
		} else {
			System.out.println("No such destination in Routing Table");
		}
	}

	void add_link_(Link l){
		this.No_links_+=1;
		this.outputlink_[No_links_-1]=l;
		if (this.routing_alg_==1){
			RoutingEntry re=new RoutingEntry(l.m_destination_.IPadd_,1);
			this.RoutingTable_.put(l.m_destination_.IPadd_, re);
		}

	}
	
	void update_routing_() {

	}
	
}
